//
//  OEHomeCollectionViewCell.m
//  OneEightyNine
//
//  Created by apple on 2019/3/6.
//  Copyright © 2019 stoneobs. All rights reserved.
//

#import "OEHomeCollectionViewCell.h"
@interface OEHomeCollectionViewCell()
@property(nonatomic, strong)UIImageView                      *iconImageView;/**<  */
@property(nonatomic, strong) STLabel                     *titleLable;/**<  */
@property(nonatomic, strong) STLabel                     *desLable;/**<  */
@property(nonatomic, strong) STButton                     *addButton;/**<  */
@property(nonatomic, strong) STLabel                     *shareLable;/**<  */
@property(nonatomic, strong) STLabel                     *typeLable;/**< 类型 */
@property(nonatomic, strong) UIView                     *line;/**< <##> */
@end
@implementation OEHomeCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self configSubView];
    }
    return self;
}
#pragma mark --configSubView
- (void)configSubView{
    UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 70, 70)];
    imageView.image = [UIImage imageNamed:@""];
    [self addSubview:imageView];
    self.iconImageView = imageView;
   
    
    self.titleLable = [[STLabel alloc] initWithFrame:CGRectMake(0, 0, 200, 30)
                                                    text:@""
                                               textColor:FirstTextColor
                                                    font:15
                                             isSizetoFit:NO
                                           textAlignment:NSTextAlignmentLeft];
    [self addSubview:self.titleLable];
    
    self.desLable = [[STLabel alloc] initWithFrame:CGRectMake(0, 0, 200, 40)
                                                text:@""
                                           textColor:SecendTextColor
                                                font:14
                                         isSizetoFit:NO
                                       textAlignment:NSTextAlignmentCenter];
    [self addSubview:self.desLable];
    
    self.shareLable = [[STLabel alloc] initWithFrame:CGRectMake(0, 0, 200, 25)
                                              text:@""
                                         textColor:SecendTextColor
                                              font:14
                                       isSizetoFit:NO
                                     textAlignment:NSTextAlignmentRight];
    [self addSubview:self.shareLable];
    
    self.addButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, 80, 25)
                                                  title:nil
                                             titleColor:SecendTextColor
                                              titleFont:12
                                           cornerRadius:0
                                        backgroundColor:nil
                                        backgroundImage:nil
                                                  image:[UIImage imageNamed:@"16×18地址"]];
    [self addSubview:self.addButton];
    self.addButton.titleEdgeInsets = UIEdgeInsetsMake(0, 3, 0, 0);
    
    
    self.typeLable = [[STLabel alloc] initWithFrame:CGRectMake(0, 0, 200, 20)
                                                text:@""
                                           textColor:OE_LIMITE_COLOR
                                                font:12
                                         isSizetoFit:NO
                                       textAlignment:NSTextAlignmentCenter];
    self.typeLable.backgroundColor = [OE_LIMITE_COLOR colorWithAlphaComponent:0.4];
    [self addSubview:self.typeLable];
    
    self.addButton.userInteractionEnabled = NO;
    
    UIView * line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 0.5)];
    line.backgroundColor = TM_lineColor;
    [self addSubview:line];
    self.line  = line;
    self.clipsToBounds = YES;
    
}
- (void)layoutSubviews{
    if (self.width < UIScreenWidth / 2) {
        // hot business
        self.iconImageView.frame = CGRectMake(0, 0, self.width, 100);
        self.titleLable.frame =   CGRectMake(3, self.iconImageView.bottom, self.width - 6, 30);
        self.desLable.frame =   CGRectMake(3, self.titleLable.bottom, self.width - 6, 40);
        
        self.addButton.frame = CGRectMake(3, self.desLable.bottom, self.width - 6, 25);
        self.shareLable.centerY = self.addButton.centerY;
        self.shareLable.right = self.width - 3;
        
        self.typeLable.hidden = YES;
        self.line.hidden = YES;
    }else{
        self.typeLable.hidden = NO;
        
        self.iconImageView.frame = CGRectMake(0, 0, 115, 115);
        CGFloat maxWitdh = self.width - self.iconImageView.right;
        self.titleLable.frame =   CGRectMake(self.iconImageView.right + 10, 0, maxWitdh, 30);
        self.desLable.frame =   CGRectMake(self.iconImageView.right + 10, self.titleLable.bottom, maxWitdh, 40);
        
        self.typeLable.frame =  CGRectMake(self.iconImageView.right + 10, self.desLable.bottom, maxWitdh, 20);
        
        
        self.addButton.frame = CGRectMake(self.iconImageView.right + 10, self.typeLable.bottom, maxWitdh, 25);
        self.shareLable.centerY = self.addButton.centerY;
        self.shareLable.right = self.width - 10;
        self.line.hidden = NO;
    }
    [NSString lableAutoAdjustWitdhWithLabel:self.typeLable];
    self.typeLable.width = self.typeLable.width + 15;
    
    self.line.bottom = self.height - 0.5;
    
    self.addButton.width = self.width / 2;
    
    if (!self.typeLable.text.length) {
        self.typeLable.hidden = YES;
    }else{
        
    }
}
- (void)setModel:(OEShopEasyModel *)model{
    _model = model;
    self.typeLable.text = model.business_cat;
    [NSString lableAutoAdjustWitdhWithLabel:self.typeLable];
    self.typeLable.width = self.typeLable.width + 15;
    
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.supplier_logo]];
    self.titleLable.text = model.supplier_name;
    self.desLable.text = model.supplier_notice;
    self.shareLable.text = [NSString stringWithFormat:@"Sales of %@",model.total_sale];
    [self.addButton setTitle:model.address forState:UIControlStateNormal];
    

}
@end
